package com.bank.backend.controller;

import com.bank.backend.annotation.AuthCheck;
import com.bank.backend.model.dto.DepositCreateDTO;
import com.bank.backend.model.dto.DepositQueryDTO;
import com.bank.backend.model.dto.DepositUpdateDTO;
import com.bank.backend.model.vo.DepositVO;
import com.bank.backend.result.PageResult;
import com.bank.backend.result.Result;
import com.bank.backend.service.DepositService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.time.LocalDate;

/**
 * 存款类型管理接口
 */
@RestController
@RequestMapping("/admin/deposits")
@Api(tags = "存款管理")
@Slf4j
public class DepositManageController {

    @Resource
    private DepositService depositService;

    /**
     * 创建存款类型
     */
    @PostMapping
    @ApiOperation("创建存款类型")
    @AuthCheck(mustRole = "管理员")
    public Result createDeposit(@RequestBody DepositCreateDTO depositCreateDTO) {
        depositService.createDeposit(depositCreateDTO);
        return Result.success(null,"存款类型创建成功");
    }

    /**
     * 分页查询存款类型
     */
    @GetMapping("/page")
    @ApiOperation("分页查询存款类型")
    @AuthCheck(mustRole = "管理员")
    public Result<PageResult<DepositVO>> pageDepositList(DepositQueryDTO queryDTO) {
        PageResult<DepositVO> result = depositService.pageDepositList(queryDTO);
        return Result.success(result);
    }

    /**
     * 根据ID查询存款类型
     */
    @GetMapping("/{depositId}")
    @ApiOperation("根据ID查询存款类型")
    @AuthCheck(mustRole = "管理员")
    public Result<DepositVO> getDepositById(@PathVariable Integer depositId) {
        DepositVO result = depositService.getDepositById(depositId);
        return Result.success(result);
    }

    /**
     * 更新存款类型
     */
    @PutMapping("/{depositId}")
    @ApiOperation("更新存款类型")
    @AuthCheck(mustRole = "管理员")
    public Result updateDeposit(@RequestBody DepositUpdateDTO depositUpdateDTO) {
        depositService.updateDeposit(depositUpdateDTO);
        return Result.success(null,"存款类型更新成功");
    }

    /**
     * 删除存款类型
     */
    @DeleteMapping("/{depositId}")
    @ApiOperation("删除存款类型")
    @AuthCheck(mustRole = "管理员")
    public Result<String> deleteDeposit(@PathVariable Integer depositId) {
        depositService.deleteDeposit(depositId);
        return Result.success("存款类型删除成功");
    }
} 